package com.system.controller;

import com.system.Tools.TimeTools;
import com.system.Tools.UserTools;
import com.system.function.object.User;
import com.system.function.object.Warehousing;
import com.system.function.service.WarehousingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/warehousing")
public class WarehousingController {

    @Autowired
    private WarehousingService WarehousingService;
    @Autowired
    private UserTools userTools;
    @Autowired
    private TimeTools timeTools;


    //查询
    @RequestMapping("/s")
    @ResponseBody
    public Map<String,Object> s(Warehousing Warehousing) {
        List<Warehousing> allWarehousing = WarehousingService.getAllWarehousing(Warehousing);
        Map<String,Object> returnMap  = new HashMap<>();
        returnMap.put("total",WarehousingService.getCountWarehousing(Warehousing));
        returnMap.put("rows",allWarehousing);
        return returnMap;
    }
    //查询
    @RequestMapping("/select")
    @ResponseBody
    public List<Warehousing> select(Warehousing Warehousing) {
        List<Warehousing> allWarehousing = WarehousingService.getAllWarehousing(Warehousing);
        return allWarehousing;
    }

    //添加
    @RequestMapping("/add")
    @ResponseBody
    public String add(HttpServletRequest request,Warehousing Warehousing) {
        User userMessageForSeesion = userTools.getUserMessageForSeesion(request);
        Warehousing.setSaveUser(userMessageForSeesion.getName());

        return WarehousingService.addWarehousing(Warehousing);
    }

    //修改
    @RequestMapping("/up")
    @ResponseBody
    public String up(Warehousing Warehousing) {
        return WarehousingService.updateWarehousing(Warehousing);
    }

    //修改
    @RequestMapping("/examineUp")
    @ResponseBody
    public String examineUp(HttpServletRequest request, Warehousing Warehousing) {
        User userMessageForSeesion = userTools.getUserMessageForSeesion(request);
        Warehousing.setExamineUser(userMessageForSeesion.getName());
        Warehousing.setExamineTime(timeTools.getTime());

        return WarehousingService.updateWarehousing(Warehousing);
    }

    //删除
    @RequestMapping("/del")
    @ResponseBody
    public String del(Warehousing Warehousing) {
        return WarehousingService.delWarehousing(Warehousing);
    }


}
